package sr.myserver.controller;

import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import sr.myserver.entity.SysRoleMenu;
import sr.myserver.service.SysRoleMenuService;
import sr.myserver.vo.common.Basic;
import sr.myserver.vo.common.PageRequest;
import sr.myserver.vo.common.PageResponse;

@Slf4j
@RestController
@RequestMapping("/sysrolemenu")
@Api(tags = "权限菜单信息")
public class SysRoleMenuController {
    private final static String K = "&";
    @Autowired
    SysRoleMenuService sysRoleMenuService;

    @GetMapping("/{id}")
    @Operation(summary = "指定ID获取数据")
    public SysRoleMenu getForm(@PathVariable("id") String id) {
        String[] ids = new String[2];
        if (id.contains(K)) {
            ids = id.split(K);
        }
        return sysRoleMenuService.getForm(ids[0], ids[1]);
    }

    @PostMapping
    @Operation(summary = "添加数据")
    public Basic.Response post(@RequestBody SysRoleMenu entity) {
        return sysRoleMenuService.add(entity);
    }

    @PutMapping("/edit")
    @Operation(summary = "指定ID修改数据")
    public Basic.Response put(@RequestBody SysRoleMenu entity) {
        return sysRoleMenuService.update(entity);
    }

    @DeleteMapping("/{roleId}")
    @Operation(summary = "指定ID删除数据")
    public Basic.Response delete(@PathVariable("roleId") String roleId) {
        return sysRoleMenuService.deleteById(roleId);
    }

    @PutMapping
    @Operation(summary = "分页列表数据")
    public PageResponse<SysRoleMenu> queryTables(@RequestBody PageRequest request) {
        return sysRoleMenuService.queryTables(request);
    }
}

